<% content_for_header render :partial => 'working_hours_navigation' %>

<script type="text/javascript">
	$(function(){
		
		/* Create a new row for creating working hour */
		var partial = '<%= render(:partial => "new_hour").lstrip.gsub(/\n/, "") %>';
		$("#add-new-row").click(function(){
			$("#add-working-hour-rows").append(partial);
		});
		
	});
</script>

<h2>Working hours</h2>

<div id="search_working_hours">
	<% form_remote_for :search, :url => search_hours_path(@user), :html => { :method => :post } do |f| %>
	<table>
		<tr>
			<td><%= f.collection_select :project_id, @user.projects.active_projects, :id, :name, { :include_blank => true, :prompt => 'Choose a Project' }, { :class => 'select_project' } %></td>
			<td><%= f.date_select :start_date, :default => { :day => 1 }, :order => [:day, :month, :year] %> - <%= f.date_select :end_date, :default => { :day => 31 }, :order => [:day, :month, :year] %></td>
			<td><%= f.submit 'Search' %></td>
		</tr>
	</table>
	<% end %>
</div>

<div id="search_info"></div>

<table id="table-headers" class="hours-expenses-table">
	<tr>
		<th width="120">Date</th>
		<th width="115">Project</th>
		<th width="116">Start time</th>
		<th width="116">End time</th>
		<th>Status</th>
	</tr>
</table>

<!--
	
	<span><a href="#" id="show_new_hour_form">Add a new hour</a></span>

<% form_for :hour, :url => { :subdomain => current_account.subdomain }, :html => { :id => 'add-working-hours', :style => 'display: none' } do |f| %>
<div id="add-hours">
	<h4>Add hours</h4>
	<table id="add-working-hour-rows" class="hours-expenses-table">
		<%= render :partial => 'new_hour' %>
	</table>
	<a href="#" id="add-new-row">Add a new row</a>
	<%= submit_tag 'Save' %> or <a href="#" id="close_new_hour_form">close</a>
	<hr/>
</div>
<% end %>

-->

<% form_for :manage_hours, :url => manage_hours_path(@user), :confirm => 'Are you sure?' do |f| %>
	<table id="working-hours" class="hours-expenses-table">
		<%= render :partial => 'hour', :collection => @working_hours %>
	</table>
	<%= custom_submit_button 'Delete', @working_hours, :name => 'manage_hour', :confirm => 'Are you sure you want to delete?', :onclick => '$("#confirmed").val("delete");', :id => 'delete_hour_button' %>
	<%= hidden_field_tag :confirmed, '' %>
	
	<% if (current_user.superior? || current_user.admin?) %>
	
	<%= custom_submit_button 'Confirm', @working_hours, :name => 'manage_hour', :confirm => 'Are you sure you want to confirm?', :onclick => '$("#confirmed").val("confirm");', :id => 'confirm_hour_button' %>
	
	<% end %>
	
	
<% end %>

<h3>Export hours</h3>

<% form_for :export_hours, :url => export_hours_path(@user), :html => { :method => :post } do |f| %>
<div id="export_hours">
	<table>
		<tr>
			<th>Hour salary</th>
			<th>Lounch break (min)</th>
		</tr>
		<tr>
			<td><%= f.text_field :salary, :size => 12 %></td>
			<td><%= f.text_field :lounch_break, :size => 12 %></td>
			<td><%= custom_submit_button 'Export', @working_hours, :id => 'export_hours_button' %></td>
		</tr>
	</table>
</div>
<% end %>
 	


